<?php

  require_once ("../accesobd.php");
 
include (dirname(dirname(__FILE__)).'/Guardado/crearpdf2.php');

    $id = $_POST["id"];
   
    
 
            
     if($id){
             $desven = "select *
              from  factura
              where nfactura='$id';";
             
            
     }   else{     
               $idd=0;
 
  $desven = "select *
              from  factura
              where nfactura>'$idd';";
             
     }
     
    $query2 = pg_query($conex,$desven) or die('Consulta fallida: ' . pg_last_error());
    
        // Redireccion
        pg_close($conex);
        //header("Location: ../../admin/gestionmesas.php")
     
  
     $cuerpo.= "<img src='../img/logo.png' /> <tr>
                        <td colspan='9' align='center'>Factura</td></tr><table border=1 >
      
                        <thead>  
                        <tr>
          

               
                                <th>Numero</th>
                                <th>Fecha Emision</th>
                                <th>Id Emp</th>
                                <th>Cedula Cliente</th>
                                <th>Impuesto</th>
                                <th>Financiamiento</th>
                                <th>Costo</th>
                                <th>Tipo pago</th>
                                <th>M pago</th>
                                <th>Precio Venta</th>
                                <th>Id Vehiculo</th>
                                 
                              
                        </tr>
                      </thead>"?>
   <?php
        
         while ($linea = pg_fetch_array($query2, null, PGSQL_ASSOC)) {
                    //Guardando tuplas en el pdf
           
             


                    $cuerpo.= "
                        <tr>
                        <td> ".$linea['nfactura']."</td>
                        <td> ".$linea['femision']."</td>
                        <td> ".$linea['idemp']." </td>
                        <td> ".$linea['cic']." </td>
                        <td> ".$linea['impuesto']."</td>
                        <td> ".$linea['financiamiento']." </td>
                          <td> ".$linea['costol']." </td>
                        <td> ".$linea['tipopago']."</td>   
                        <td> ".$linea['mpago']." </td>         
                        <td> ".$linea['precioventa']."</td> 
                        <td> ".$linea['idveh']."</td>
                        
                        </tr>";
         }  
         
          
                 $cuerpo.= "</table>";
                
              crear_pdf($cuerpo,'facturass');
              
     
?>